#include "RedSoldierState.h"




void RedSoldierState::_updateSprites()
{
	int soldierDirection;

	double targetX = _armyData->targetRect->X;
	double targetY = _armyData->targetRect->Y;

	double soldierX = _armyData->getRect()->X;
	double soldierY = _armyData->getRect()->Y;

	// Check left or right 
	if (targetX < soldierX) {
		soldierDirection = _SOLDIER_DIRECTION_LEFT;
	}
	else {
		soldierDirection = _SOLDIER_DIRECTION_RIGHT;
	}
	// check up or down
	if (targetY > soldierY + _DATA_SOLDIER_DELTA_UP) {
		soldierDirection += 2;
	} else if (targetY < soldierY - _DATA_SOLDIER_DELTA_UP) {
		soldierDirection += 4;
	}

	_armyData->sprites->currentSprite->setIndex(soldierDirection);
}

void RedSoldierState::initSprites()
{
	_armyData->initSpriteHandler();
	_armyData->sprites->addSprite(1, _ID_ARMY_RED_SOLDIER, 0);
	_armyData->sprites->setState(1);
}

void RedSoldierState::draw(long timetick)
{
	_armyData->sprites->draw();
	_armyData->bulletContainer->draw(0);
}

void RedSoldierState::update(long timetick)
{
	if(_armyData->deaded == true)
	{
		return;
	}
	if (_armyData->isDead)
	{
		_armyData->deaded = true;
		EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Burning, _armyData->getRect()->X, _armyData->getRect()->Y);
	}
	_updateSprites();
}
